package com.example.config.demo;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

import javax.sql.DataSource;

/**
 * @author yuisama
 * @date 2023/02/01 18:37
 **/
@Slf4j
@Configuration
public class AppConfig {
    @Bean
    public DataSource dataSource(@Autowired MySQLConfig config){
        MysqlDataSource dataSource = new MysqlDataSource();
        log.debug("MYSQL 配置如下：" + config);
        dataSource.setUrl(config.getUrl());

        dataSource.setUser(config.getUsername());
        dataSource.setPassword(config.getPassword());

        return dataSource;

    }
}

